route.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest, NextResponse } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. import { handle as iflytekHandler } from "../../iflytek";
  13. async function handle(
  14. req: NextRequest,
  15. { params }: { params: { provider: string; path: string[] } },
  16. ) {
  17. const apiPath = `/api/${params.provider}`;
  18. console.log(`[${params.provider} Route] params `, params);
  19. switch (apiPath) {
  20. case ApiPath.Azure:
  21. return azureHandler(req, { params });
  22. case ApiPath.Google:
  23. return googleHandler(req, { params });
  24. case ApiPath.Anthropic:
  25. return anthropicHandler(req, { params });
  26. case ApiPath.Baidu:
  27. return baiduHandler(req, { params });
  28. case ApiPath.ByteDance:
  29. return bytedanceHandler(req, { params });
  30. case ApiPath.Alibaba:
  31. return alibabaHandler(req, { params });
  32. // case ApiPath.Tencent: using "/api/tencent"
  33. case ApiPath.Moonshot:
  34. return moonshotHandler(req, { params });
  35. case ApiPath.Stability:
  36. return stabilityHandler(req, { params });
  37. case ApiPath.Iflytek:
  38. return iflytekHandler(req, { params });
  39. default:
  40. return openaiHandler(req, { params });
  41. }
  42. }
  43. export const GET = handle;
  44. export const POST = handle;
  45. export const runtime = "edge";
  46. export const preferredRegion = [
  47. "arn1",
  48. "bom1",
  49. "cdg1",
  50. "cle1",
  51. "cpt1",
  52. "dub1",
  53. "fra1",
  54. "gru1",
  55. "hnd1",
  56. "iad1",
  57. "icn1",
  58. "kix1",
  59. "lhr1",
  60. "pdx1",
  61. "sfo1",
  62. "sin1",
  63. "syd1",
  64. ];